package com.xiaoyao.novel.service;

import java.util.List;

import com.xiaoyao.novel.common.Pagin;
import com.xiaoyao.novel.pojo.Book;
import com.xiaoyao.novel.pojo.Chapter;
import com.xiaoyao.novel.util.HtmlStatic;

public class StaticService {

	BookService bookService = new BookService();
	ChapterService chapterService = new ChapterService();

	public void staticTopNChapter(int n) {
		List<Book> bookList = bookService.getAll();
		for (Book book : bookList) {
			Pagin pagin = new Pagin();
			pagin.setPageSize(n);
			pagin.getSearchParam().put("orderBy", " cid desc ");
			pagin.getSearchParam().put("bookId", "" + book.bookId);
			List<Chapter> chapters = chapterService.search(pagin);
			for (Chapter chapter : chapters) {
				HtmlStatic.staticChapter(chapter,false);
			}
		}
	}

	public void staticTopNChapter(int bookId, int n) {
		if (n<0) {
			n=0;
		}
		Pagin pagin = new Pagin();
		pagin.setPageSize(n); 
		pagin.getSearchParam().put("orderBy", " cid desc ");
		pagin.getSearchParam().put("bookId", "" + bookId);
		List<Chapter> chapters = chapterService.search(pagin);
		for (Chapter chapter : chapters) {
			HtmlStatic.staticChapter(chapter,true);
		}
	}
}
